﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Resources;
using System.Globalization;
using System.Threading;
using System.Reflection;

namespace BlobTowerDefense.Resources
{
    public class ApplicationResources : IValueConverter
    {
        private static readonly ResourceManager resourceManager = new ResourceManager("BlobTowerDefense.Resources.Strings",
                                                                      Assembly.GetExecutingAssembly());

        /// <summary>
        /// Use this property to specify the culture
        /// </summary>
        private static CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture;
        public static CultureInfo UiCulture
        {
            get { return uiCulture; }
            set { uiCulture = value; }
        }

        /// <summary>
        /// This method returns the localized string of the given resource.
        /// </summary>
        public static string Get(string resource)
        {
            return resourceManager.GetString(resource, UiCulture);
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var reader = (ApplicationResources)value;
            return Get((string)parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // ConvertBack is not used, because the Localization is only a One Way binding
            throw new NotImplementedException();
        }
    }
}
